package com.iwunu.auth.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class JwtConfig {
	/** jwt 安全Key ，默认：mxb@#$0315  **/
	@Value("${yzaan.auth.jwt.secretKey:mxb@#$0315}")
	private String secretKey;
	/** jwt header Key，默认：Authorization  **/
	@Value("${yzaan.auth.jwt.headerKey:Authorization}")
	private String headerKey;
	/** jwt header 前缀，默认：Bearer  **/
	@Value("${yzaan.auth.jwt.headerPrefix:Bearer}")
	private String headerPrefix;
	/** jwt 超时时间，默认：7天  **/
	@Value("${yzaan.auth.jwt.expiration:1800000}")
	private long expiration;
	/** jwt 拦截跳过请求  **/
	@Value("${yzaan.auth.jwt.permitAll:}")
	private String permitAll;
	/** jwt 令牌刷新时间，单位：秒，默认：0  **/
	@Value("${yzaan.auth.jwt.refreshTime:0}")
	private long refreshTime;
	/** jwt 令牌宽限时间，单位：秒，默认：0  **/
	@Value("${yzaan.auth.jwt.expirationExpand:0}")
	private long expirationExpand;
	/** jwt 发行人 **/
	@Value("${yzaan.auth.jwt.issuer:}")
	private String issuer;
	
	private int headerPrefixLength=-1;
	
	public int headerPrefixLength() {
		if(headerPrefixLength<0) {
			headerPrefixLength = headerPrefix==null?0:headerPrefix.length();
		}
		return headerPrefixLength;
	}
	
	public String getSecretKey() {
		return secretKey;
	}
	public void setSecretKey(String secretKey) {
		this.secretKey = secretKey;
	}
	public String getHeaderKey() {
		return headerKey;
	}
	public void setHeaderKey(String headerKey) {
		this.headerKey = headerKey;
	}
	public String getHeaderPrefix() {
		return headerPrefix;
	}
	public void setHeaderPrefix(String headerPrefix) {
		this.headerPrefix = headerPrefix;
	}
	public long getExpiration() {
		return expiration;
	}
	public void setExpiration(long expiration) {
		this.expiration = expiration;
	}
	public String getPermitAll() {
		return permitAll;
	}
	public void setPermitAll(String permitAll) {
		this.permitAll = permitAll;
	}
	public long getRefreshTime() {
		return refreshTime;
	}
	public void setRefreshTime(long refreshTime) {
		this.refreshTime = refreshTime;
	}
	
	public long getExpirationExpand() {
		return expirationExpand;
	}

	public void setExpirationExpand(long expirationExpand) {
		this.expirationExpand = expirationExpand;
	}

	public String getIssuer() {
		return issuer;
	}

	public void setIssuer(String issuer) {
		this.issuer = issuer;
	}

	@Override
	public String toString() {
		return "JwtConfig [secretKey=" + secretKey + ", headerKey=" + headerKey + ", headerPrefix=" + headerPrefix
				+ ", expiration=" + expiration + ", permitAll=" + permitAll + ", refreshTime=" + refreshTime
				+ ", expirationExpand=" + expirationExpand + ", issuer=" + issuer + "]";
	}
}
